Pymatgen supports reading of most common file formats, including the Crystallographic Information File and various input and output files of computational codes like VASP. However, it is often easier and quicker to directly query for structures from online sources. Though private databases such as the Inorganic Crystal Structure Database are not open, there are open sources such as the Materials Project and the Crystallographic Open Database (COD) where one can obtain crystal structures.
Written using:
In [1]:
from pymatgen.ext.matproj import MPRester
# Note that you will need to add your Materials API key in your .pmgrc.yaml file as "PMG_MAPI_KEY".
# Alternatively, you will need to supply the API key as an arg to MPRester.
mpr = MPRester()
In [2]:
# Querying by formula only.
structures = mpr.get_structures("Li2O")
print(structures)
In [3]:
# Querying by chemical system only.
structures = mpr.get_structures("Li-O")
for s in structures:
print(s.formula)
# A number of Li-O structures are returned with different Li:O ratios.
In [4]:
from pymatgen.ext.cod import COD
cod = COD()
In [5]:
structure = cod.get_structure_by_id(1010064)
print(structure)
In [6]:
structures = cod.get_structure_by_formula("Li2O")
for d in structures:
print("COD ID: %d, Formula: %s, Spacegroup: %s" % (d["cod_id"], d["structure"].formula, d["sg"]))
In [7]:
print(structures[0]["structure"])
In [ ]: